unit uFormBaseMessage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uFormBase, AppEvnts, JvComponentBase, JvBalloonHint, Menus,
  JvMenus, ImgList, JvImageList, ActnList, JvVersionControlActions, ExtCtrls,
  JvExExtCtrls, JvImage, JvExControls, JvButton, JvTransparentButton,
  JvExtComponent, JvPanel, JvGradientHeaderPanel, uFormBaseDialog,
  dxGDIPlusClasses, JvLabel, JvExForms, JvScrollBox, StdCtrls, JvExStdCtrls,
  JvMemo, JvScrollText, JvaScrollText, ComCtrls, pngimage;

type
  TfFormBaseMessage = class(TfFormBase)
    JvImageWarning: TJvImage;
    JvImageError: TJvImage;
    JvImageConfirmation: TJvImage;
    JvImageInformation: TJvImage;
    JvMemoText: TRichEdit;
    tbtnOK: TJvTransparentButton;
    tbtnCancel: TJvTransparentButton;
    actOk: TAction;
    actYes: TAction;
    actCancel: TAction;
    actNo: TAction;
   procedure jvPResizeFormResize(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure actCloseFormExecute(Sender: TObject);
    procedure actOkExecute(Sender: TObject);
    procedure actYesExecute(Sender: TObject);
    procedure actCancelExecute(Sender: TObject);
    procedure actNoExecute(Sender: TObject);
  private
    { Private declarations }
     DialogType : TMyDialogType;
     MessageButton : TMyMessageButton;
     TextMessage : AnsiString;
     CaptionMessage : AnsiString;
     procedure SetImageDialogType(_image : TJvImage; _visibe : boolean);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent; AText, ACaption : AnsiString; ADialogType : TMyDialogType; AMessageButton : TMyMessageButton); virtual;//override;
  end;

var
  fFormBaseMessage: TfFormBaseMessage;

implementation

{$R *.dfm}

procedure TfFormBaseMessage.actCancelExecute(Sender: TObject);
begin
  inherited;
  Self.ModalResult := mrCancel;
end;

procedure TfFormBaseMessage.actCloseFormExecute(Sender: TObject);
begin
  inherited;
  Self.ModalResult := mrClose;
end;

procedure TfFormBaseMessage.actNoExecute(Sender: TObject);
begin
  inherited;
  Self.ModalResult := mrNo;
end;

procedure TfFormBaseMessage.actOkExecute(Sender: TObject);
begin
  inherited;
  Self.ModalResult := mrOk;
end;

procedure TfFormBaseMessage.actYesExecute(Sender: TObject);
begin
  inherited;
  Self.ModalResult := mrYes;
end;

constructor TfFormBaseMessage.Create(AOwner: TComponent; AText, ACaption : AnsiString; ADialogType : TMyDialogType; AMessageButton : TMyMessageButton);
begin
  inherited MyCreate(AOwner, MyBsDialog);

  DialogType := ADialogType;
  MessageButton := AMessageButton;
  TextMessage := AText;
  CaptionMessage := ACaption;

  //ustawienie rodzaju ikonki komunikatu
  case DialogType of
    MyDtNone:
              begin
                SetImageDialogType(JvImageWarning, false);
                SetImageDialogType(JvImageError, false);
                SetImageDialogType(JvImageInformation, false);
                SetImageDialogType(JvImageConfirmation, false);
              end;
    MyDtWarning:      SetImageDialogType(JvImageWarning, true);
    MyDtError:        SetImageDialogType(JvImageError, true);
    MyDtInformation:  SetImageDialogType(JvImageInformation, true);
    MyDtConfirmation: SetImageDialogType(JvImageConfirmation, true);
  end;

  //ustawienie rozmaru okna
  Self.Height := 150;
  Self.Width := 350;

  //ustawine buttonow
  tbtnOK.Top := JvGradientHeaderPanelMaster.Height - tbtnOK.Height - 5;
  tbtnCancel.Top := tbtnOK.Top;
  case AMessageButton of
    MyMbOK :  begin
                tbtnOK.Visible := true;
                tbtnOK.Action := actOk;
                tbtnOK.Left := Round(JvGradientHeaderPanelMaster.Width/2) - Round(tbtnOK.Width/2);
              end;
    MyMbCancel :  begin
                    tbtnCancel.Visible := true;
                    tbtnCancel.Action := actCancel;
                    tbtnOK.Visible := true;
                    tbtnOK.Action := actOk;
                  end;
    MyMbYes : begin
                tbtnOK.Visible := true;
                tbtnOK.Action := actYes;
              end;
    MyMbNo : begin
                tbtnCancel.Visible := true;
                tbtnCancel.Action := actNo;
                tbtnOK.Visible := true;
                tbtnOK.Action := actYes;
              end;
  end;

  //jesli nie ma zadnej ikonki to tekst rozciagamy
  if DialogType = MyDtNone then
    JvMemoText.Left := 6
  else
    JvMemoText.Left := 62;
  JvMemoText.Width := Self.Width - JvMemoText.Left - 6;
  JvMemoText.Height := Self.Height - JvMemoText.Top - jvGHPanelTop.Height - 6;
  JvMemoText.Color := JvGradientHeaderPanelMaster.GradientStartColor;
  ActiveControl := jvPanelTop;
end;

procedure TfFormBaseMessage.SetImageDialogType(_image : TJvImage; _visibe : boolean);
begin
  _image.Visible := _visibe;
  _image.Top := 6;
  _image.Left := 6;
end;

procedure TfFormBaseMessage.FormShow(Sender: TObject);
var
  _label : TJvLabel;
begin
  inherited;

  JvMemoText.Lines.Clear;
  JvMemoText.Lines.Text := trim(string(TextMessage));

  //liczymi ile ejst lini do ukazana scrollball
//  while not (GetWindowLong(JvMemoText.Handle, GWL_STYLE) and WS_VSCROLL <> 0) do
//  begin
//    JvMemoText.Height := JvMemoText.Height - 1;
//    JvMemoText.t
//    JvMemoText.Refresh;
//  end;

  _label := TJvLabel.Create(nil);
  try
    _label.AutoSize := true;
    _label.Caption := trim(string(TextMessage));

//    if (_label.Height * (JvMemoText.Lines.Count + JvMemoText.Lines.Count)) < JvGradientHeaderPanelMaster.Height then
    begin
      JvMemoText.Height := tbtnOK.Top - JvMemoText.Top - 5;
//      JvMemoText.Height := JvGradientHeaderPanelMaster.Height  - tbtnOK.Top;
      //_label.Height * (JvMemoText.Lines.Count + JvMemoText.Lines.Count);

      //JvMemoText.Top := Round(JvGradientHeaderPanelMaster.Height/3) - Round(JvMemoText.Height/2);
    end;
  finally
    _label.Free;
  end;

  if CaptionMessage <> '' then
    jvGHPanelTop.LabelCaption := string(CaptionMessage)
  else
    jvGHPanelTop.LabelCaption := Application.Title;
  Self.Caption := jvGHPanelTop.LabelCaption;
end;

procedure TfFormBaseMessage.jvPResizeFormResize(Sender: TObject);
begin
  inherited FormResize(Sender);
end;

end.
